package org.dromara.quick.chat.controller;

import io.swagger.v3.oas.annotations.Operation;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.utils.ip.RegionUtils;
import org.dromara.common.web.core.BaseController;
import org.dromara.quick.chat.model.bo.create.ImSocialCommentBO;
import org.dromara.quick.chat.model.bo.query.ImSocialCommentQueryBO;
import org.dromara.quick.chat.service.ImSocialCommentService;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: Stars
 * @description 针对表【im_social_comment(社交软件中的评论表，用于存储用户对各种主题的评论信息)】的数据库操作Service
 * @Date: 2025/3/6 22:33
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("/im/ban/record")
public class ImSocialCommentController extends BaseController {

    private final ImSocialCommentService imSocialCommentService;

    /**
     * 点赞用户的评论
     * @param commentId 评论的id
     */
    @Operation(summary = "点赞用户的评论")
    @GetMapping("/comment/like")
    public R<?> commentLike(Long commentId) {
        if (commentId == null){
            return R.fail("参数错误");
        }
        imSocialCommentService.commentLike(commentId);
        return R.ok();
    }

    /**
     * 添加评论
     */
    @Operation(summary = "添加评论")
    @PostMapping("/comment/add")
    public R<?> addComment(@RequestBody ImSocialCommentBO imSocialCommentBO, HttpServletRequest request) {
        String clientIp = RegionUtils.getClientIp(request);
        String province = RegionUtils.extractProvince(clientIp);
        imSocialCommentBO.setIpLocation(province);
        imSocialCommentService.addComment(imSocialCommentBO);
        return R.ok();
    }

    /**
     * 获取评论列表
     */
    @Operation(summary = "获取评论列表")
    @GetMapping("/comment/list")
    public R<?> listComment(ImSocialCommentQueryBO imSocialCommentQueryBO) {
        if (imSocialCommentQueryBO.getSocialPostId() == null){
            return R.fail("参数错误");
        }
        return R.ok(imSocialCommentService.list(imSocialCommentQueryBO));
    }
}
